load("//bazel:macros.bzl", "bool_flag", "exports_files_legacy", "selects", "skia_cc_deps", "split_srcs_and_hdrs")

licenses(["notice"])

exports_files_legacy()

filegroup(
    name = "txts",
    srcs = [
        "generated/sksl_compute.dehydrated.sksl",
        "generated/sksl_frag.dehydrated.sksl",
        "generated/sksl_gpu.dehydrated.sksl",
        "generated/sksl_graphite_frag.dehydrated.sksl",
        "generated/sksl_graphite_vert.dehydrated.sksl",
        "generated/sksl_public.dehydrated.sksl",
        "generated/sksl_rt_shader.dehydrated.sksl",
        "generated/sksl_shared.dehydrated.sksl",
        "generated/sksl_vert.dehydrated.sksl",
    ],
    visibility = ["//:__subpackages__"],
)

CORE_SRCS = [
    "SkSLAnalysis.cpp",
    "SkSLAnalysis.h",
    "SkSLBuiltinMap.cpp",
    "SkSLBuiltinMap.h",
    "SkSLBuiltinTypes.cpp",
    "SkSLBuiltinTypes.h",
    "SkSLCompiler.cpp",
    "SkSLCompiler.h",
    "SkSLConstantFolder.cpp",
    "SkSLConstantFolder.h",
    "SkSLContext.cpp",
    "SkSLContext.h",
    "SkSLDSLParser.cpp",
    "SkSLDSLParser.h",
    "SkSLDehydrator.cpp",
    "SkSLDehydrator.h",
    "SkSLErrorReporter.cpp",
    "SkSLFileOutputStream.h",
    "SkSLGLSL.h",
    "SkSLInliner.cpp",
    "SkSLInliner.h",
    "SkSLIntrinsicList.h",
    "SkSLLexer.cpp",
    "SkSLLexer.h",
    "SkSLMangler.cpp",
    "SkSLMangler.h",
    "SkSLMemoryLayout.h",
    "SkSLMemoryPool.h",
    "SkSLModifiersPool.h",
    "SkSLOperator.cpp",
    "SkSLOutputStream.cpp",
    "SkSLOutputStream.h",
    "SkSLParsedModule.h",
    "SkSLPool.cpp",
    "SkSLPool.h",
    "SkSLPosition.cpp",
    "SkSLProgramSettings.h",
    "SkSLRehydrator.cpp",
    "SkSLRehydrator.h",
    "SkSLSampleUsage.cpp",
    "SkSLSharedCompiler.cpp",
    "SkSLSharedCompiler.h",
    "SkSLString.cpp",
    "SkSLStringStream.h",
    "SkSLThreadContext.cpp",
    "SkSLThreadContext.h",
    "SkSLUtil.cpp",
    "SkSLUtil.h",
    "spirv.h",
]

split_srcs_and_hdrs(
    name = "core",
    files = CORE_SRCS,
)

selects.config_setting_group(
    name = "needs_sksl",
    match_any = [
        "//src/gpu:has_gpu_backend",
        ":enable_sksl_true",
    ],
    visibility = ["//:__subpackages__"],
)

selects.config_setting_group(
    name = "use_sksl_gpu_srcs",
    match_any = [
        "//src/gpu:has_gpu_backend",
        ":enable_skslc_true",
    ],
    visibility = ["//:__subpackages__"],
)

bool_flag(
    default = False,
    flag_name = "enable_sksl",
)

bool_flag(
    default = False,
    flag_name = "enable_skslc",
)

bool_flag(
    default = False,
    flag_name = "enable_sksl_tracing",
)

filegroup(
    name = "srcs",
    srcs = [
        ":core_srcs",
        "//src/sksl/analysis:srcs",
        "//src/sksl/codegen:srcs",
        "//src/sksl/dsl:srcs",
        "//src/sksl/ir:srcs",
        "//src/sksl/tracing:srcs",
        "//src/sksl/transform:srcs",
    ],
    visibility = ["//src:__pkg__"],
)

filegroup(
    name = "private_hdrs",
    srcs = [
        ":core_hdrs",
        "//src/sksl/analysis:private_hdrs",
        "//src/sksl/codegen:private_hdrs",
        "//src/sksl/dsl:private_hdrs",
        "//src/sksl/ir:private_hdrs",
        "//src/sksl/tracing:private_hdrs",
        "//src/sksl/transform:private_hdrs",
    ] + select({
        ":use_sksl_gpu_srcs": [
            "GLSL.std.450.h",
        ],
        "//conditions:default": [],
    }),
    visibility = ["//src:__pkg__"],
)

skia_cc_deps(
    name = "deps",
    textual_hdrs = [
        ":txts",
    ],
    visibility = ["//src:__pkg__"],
    deps = [
        "//src/sksl/codegen:deps",
    ] + select({
        "//src/sksl:enable_skslc_true": [
            "@spirv_tools",
            "@dawn//:tint",
        ],
        "//conditions:default": [],
    }),
)
